package com.nowcoder.community;

/**
 * @author szq
 * @create 2023-01-24 0:23
 * @description
 */
public class Solution {
    public static int removeElement(int[] nums, int val) {
        int left = 0;
        int right = nums.length;
        while (left < right) {
            if (nums[left] == val) {
                nums[left] = nums[right - 1];
                right--;
            } else {
                left++;
            }
        }
        return left;
    }

    public static int searchInsert(int[] nums, int target) {
        int left, right, mid = 0;
        left = 0;
        right = nums.length - 1;
        int ans = nums.length;
        while (left <= right) {
            mid = (left + right) / 2;
            if (target <= nums[mid]) {
                right = mid - 1;
                ans = mid;
            } else if (target > nums[mid]) {
                left = mid + 1;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        int[] nums = {1, 3, 5, 6};
        int i = searchInsert(nums, 0);
        System.out.println(i);
    }
}
